home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
QRZ! Ham Radio 6
/
QRZ Ham Radio Callsign Database - Volume 6.iso
/
mac
/
files
/
amiga
/
csrc720j.lzh
/
mbinit.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-13
|
18KB
|
832 lines
/*
* MBINIT.C - 06/28/92 - Read configuration file.
*/
#include "mb.h"
#ifdef MCH_AMIGA
#include <exec/memory.h>
extern char *ser_dev_name;
extern long unit;
char dev_name[20];
extern char tmpstr[];
extern int numpass,debug;
extern int ln_jstr;
extern char *vers;
/* Current options.
NOTE: You can't use this to control options in the opening of windows
or the serial line etc. because they are opened BEFORE the init()
routine is called, which is where these flags are initially set.
0 A Reject unwanted bulletins if there's no bbs.dis file.
1 B Replace @bbs field with content of user BBS if they are on file.
2 C Prevent use of FBB compression which requires transparent mode.
3 D Open the window without borders ... for those, like me, that
like a full-width 80 column screen
4 E Turn off interflag so that users can't abort output (just in case
there's a bug).
5 F Don't show any titles at all in the window.
6 G Don't use REXX ... usually for older Kickstarts (1.3) that don't
have it.
*/
/* There should be NUMOPTS ones in the initialization of optflags */
#define NUMOPTS 10
char optflags[NUMOPTS] = {1,1,1,1,1,1,1,1,1,1};
extern char hostport;
#endif
#define minheap 8192
#define minscr 4096
#define maxscr 14336
/*
* Read one line from the configuration file.
* The first field is a number. Return it.
*/
rdnumb()
{
fgets (port->line, linelen, port->fl);
parse ();
return atoi (port->fld[0]);
}
/*
* Read one line from the configuration file.
* The first field is a YES / NO keyword.
* Return true if Y, false if N.
*/
kw()
{
fgets(port->line, linelen, port->fl);
parse();
return(*port->fld[0] is 'Y');
}
/*
* Read one line from the configuration file.
* The first field is a letter.
* Return the control character corresponding to that letter.
*/
char cchr()
{
fgets (port->line, linelen, port->fl);
return (*port->line - 64);
}
/*
* Read one line from the configuration file.
* Squirrel it away in allocated memory.
* Return a pointer to it.
*/
char *rdstr()
{
fgets (port->line, linelen, port->fl);
return strdup(port->line);
}
/*
* Read a line from the configuration file.
* Remove the new line at end.
* Squirrel it away in allocated memory.
* Return a pointer to it.
*/
char *rdstrnl()
{
fgets (port->line, linelen, port->fl);
remnl(port->line);
return strdup(port->line);
}
/*
* Read multiple lines from the configuration file, until "*** EOF".
* Squirrel them away in allocated memory in MLM structure.
* Return a pointer to the structure.
*/
MLM *rdmstr()
{
register MLM *h, *m, *t;
h = NULL;
fgets (port->line, linelen, port->fl);
while (!iseof(port->line))
{
m = (MLM *) malloc(sizeof(MLM));
if (h is NULL) h = m; else t->next = m;
m->next = NULL;
t = m;
m->text = strdup(port->line);
fgets(port->line, linelen, port->fl);
}
return h;
}
/*
* Read multiple lines from the hold file.
* Build the message hold list.
*/
rdhold()
{
register HOLD *hp;
FILE *holdfl;
hold = NULL;
if ((holdfl = fopen("HOLD.MB", "r")) is NULL)
{
printf("No Hold File\n");
return;
}
printf("Held Calls ");
while (fgets (port->line, linelen, holdfl))
{
hp = (HOLD *)malloc(sizeof(HOLD));
hp->next = hold; hold = hp;
parse();
printf("%s ", port->fld[0]);
pcall(hp->call, port->fld[0]);
}
fclose(holdfl);
printf("\n");
}
/*
* Read multiple lines from the configuration file, until "*** EOF".
* Build the @ BBS translation list.
*/
rdxbbs()
{
register XBBS *xp;
xbbs = NULL;
fgets (port->line, linelen, port->fl);
while (!iseof(port->line))
{
xp = (XBBS *)malloc(sizeof(XBBS));
xp->next = xbbs; xbbs = xp;
parse();
pcall(xp->from, port->fld[0]);
if (port->flds is 1) fill(xp->to, ' ', ln_call);
else pcall(xp->to, port->fld[1]);
fgets (port->line, linelen, port->fl);
}
}
/*
* Read the directory path section of the configuration file.
*/
rdpaths()
{
register DIRPATH *p, *path;
register char *st;
dphd = NULL;
fgets(port->line, linelen, port->fl);
while (!iseof(port->line))
{
path = (DIRPATH *) malloc(sizeof(DIRPATH));
path->next = NULL;
if (dphd is NULL) dphd = path; else p->next = path;
p = path;
parse();
st = port->fld[0];
path->flags = 0;
path->id = *st++;
while(*st)
{
switch(*st)
{
case 'D': path->flags setbit dp_dnload; break;
case 'U': path->flags setbit dp_upload; break;
default : ;
}
st++;
}
path->path = rdstrnl();
path->name = rdstrnl();
fgets(port->line, linelen, port->fl);
}
}
/*
* Read the port definition section of the configuration file.
*/
#ifdef MCH_AMIGA
/* NOTE - that this routine is now executed BEFORE the window is opened
and so any information it prints must be done with printf ... NOT with
ttputs or ttputc.
*/
#endif
rdports()
{
register PORTS *p, *pt;
register char *st;
short first = true;
#ifndef MCH_AMIGA
word mask = 0x0000000000000001;
#else
word mask = 1;
#endif
word pflg;
p_window = 0;
pt = porthd;
fgets (port->line, linelen, port->fl);
while (!iseof(port->line))
{
#ifdef MCH_AMIGA
/* If this is 'mb' then only read the console port and the port we are
going to be connected to.
If this is sysop, then read all of them so that the A command can work.
*/
#ifndef MCH_SYSOP
st = port->line;
if((toupper(*st) != 'Z') && (toupper(*st) != hostport)) {
fgets (port->line, linelen, port->fl);
fgets (port->line, linelen, port->fl);
continue;
}
#endif
#endif
parse();
if (!first)
{
pt = (PORTS *) malloc(sizeof(PORTS));
pt->cmd = (char *)malloc(cmdlen);
pt->line = (char *)malloc(linelen);
p->next = pt;
}
first = false;
p = pt;
pt->next = NULL;
p->mode = idle;
p->lport = NULL;
pt->user = (USER *)malloc(sizeof(USER));
pt->user->rn = 0;
pt->mmhs = (MSG_HDR *)malloc(sizeof(MSG_HDR));
pt->mmhs->rn = 0;
pt->cmdcnt = 0;
pt->msg = NULL;
st = port->fld[0];
pt->dev = 0;
pt->priv = 0;
pt->flags = p_give | p_dotmr;
pt->ecmon = false;
pt->eccmds = false;
pt->ecuser = false;
pt->tmode = false;
#ifndef MCH_AMIGA
pt->id = *st++;
#else
pt->id = toupper(*st++);
#endif
pt->idn = (int)(pt->id - 'A');
if (pt->idn < 16) p_window setbit (mask << pt->idn);
while(*st)
{
switch(*st)
{
/*
* Device type.
*/
case 'C': pt->dev = p_console; cport = pt; break;
case 'S': pt->dev = p_serial; break;
case 'T': pt->dev = p_tnc; break;
#ifdef MCH_AMIGA
case 'N': pt->dev = p_nulmdm; break;
#endif
/*
* Device characteristics.
*/
case 'E': pt->flags setbit p_echo; break;
case 'L': pt->flags setbit p_lf; break;
case '1': pt->ecmon = true; break;
case '2': pt->ecuser = true; break;
case '3': pt->eccmds = true; break;
case 'X': pt->tmode = true; break;
/*
* Port priveleges and permissions.
*/
case 'B': pt->priv setbit p_bbs; break;
case 'D': pt->priv setbit p_dnload; break;
case 'G': pt->priv setbit p_gate; break;
case 'I': pt->priv setbit p_ilcal; break;
case 'M': pt->priv setbit p_mon; break;
case 'R': pt->priv setbit p_sysop; break;
case 'U': pt->priv setbit p_upload; break;
#ifdef MCH_AMIGA
/* Turn off one of my optional fixes */
case '#':
st++;
if((toupper(*st) >= 'A') && (toupper(*st) <= ('A' + NUMOPTS-1))){
optflags[toupper(*st) - 'A'] = 0;
}
break;
#endif
}
st++;
}
pt->mode = idle;
pt->ctime = atoi(port->fld[1]);
pt->dtime = atoi(port->fld[2]);
pt->mtime = atoi(port->fld[3]);
pt->mcount = atoi(port->fld[4]);
pt->maxhrd = atoi(port->fld[5]);
pt->ndigi = atoi(port->fld[6]);
pt->fwdmin = atoi(port->fld[7]);
pt->errmax = atoi(port->fld[8]);
pt->ftime = atoi(port->fld[9]);
pt->nhrd = 0;
#ifndef MCH_AMIGA
pt->heard = (char *) malloc(17 * pt->maxhrd);
#else
pt->heard = (char *) malloc(ln_jstr * pt->maxhrd);
#endif
#ifdef MCH_AMIGA
/* If this is 'mb' then read the optional device name and unit number.
If it is already set then don't override it.
sysop ignores it because it can't address the devices anyway
*/
#ifndef MCH_SYSOP
if(!ser_dev_name && (pt->id != 'Z')) {
if(*port->fld[10])unit = atol(port->fld[10]);
/* If unit number still not set then make it zero here so that when I
print out the unit number it won't be -1.
*/
if(unit == -1)unit = 0;
if(*port->fld[11]) {
strcpy(dev_name,port->fld[11]);
strlwr(dev_name);
ser_dev_name = &dev_name[0];
}
}
#endif
#endif
pt->name = rdstrnl();
pt->ec = pt->ecmon;
fgets(port->line, linelen, port->fl);
}
#ifndef MCH_AMIGA
pflg = getp_flag();
putp_flag (pflg setbit p_window);
printf ("Window %X port flag %X\n", p_window, pflg);
ioinit();
/*
* Drain any garbage from the port.
*/
for (p = porthd; p isnt NULL; p = p->next)
{
ioport(p);
switch(p->dev)
{
case p_tnc :
while(instat()) inchar();
p->mode = remote;
if (p->tmode) p->flags setbit p_trans;
distnc();
p->mode = idle;
break;
case p_serial :
case p_console:
while(instat()) inchar();
default : ;
}
}
#endif
#ifndef MCH_SYSOP
/* If option C is turned off then remove the 'B', if it is there, in
the version string to prevent FBB compression.
*/
if(!optflags[2]) {
st = vers;
while(*st != '-')st++;
st++;
while(*st != '-')st++;
st++;
while((*st != 'B') && (*st != ']'))st++;
if(*st == 'B') {
do {
*st = *(st+1);
st++;
} while(*st);
}
}
ioport(porthd);
#else
cport->fl = port->fl;
ioport(cport);
#endif
printf("\n");
}
/*
* Do the initialization. Called from mainline.
*/
init(file)
char *file;
{
word avl;
#ifdef MCH_AMIGA
word fast;
char tstr[100];
#endif
/*
* Set default system params.
*/
s_param = s_page;
s_prompt = 0;
/*
* Need structure for parse, so allocate a port.
*/
#ifndef MCH_AMIGA
porthd = (PORTS *) malloc(sizeof(PORTS));
porthd->cmd = (char *) malloc(cmdlen);
porthd->line = (char *) malloc(linelen);
ioport(porthd);
/*
* Open the configuration file.
*/
if ((port->fl = fopen(file, "r")) is NULL)
{
printf("Cannot open %s\n", file); exit(1);
}
/*
* Read the configuration file, set everything up.
*/
rdports();
#else
ioinit(); /* This was done in rdports but must be done here */
#endif
rdpaths();
rdxbbs();
rdhold();
rdcnf();
fclose(port->fl);
ioport(cport);
opnmon();
opnmsg();
opnusr();
opnbid();
rduser(tcall, cport->user);
/*
* If owners user record did not exist, make him one of the right kind.
*/
if (!cport->user->rn)
{
cport->user->options = u_bbs | u_sysop | u_local;
strncpy(cport->user->home_bbs, tcall, ln_call);
upduser(cport->user);
}
opnlog();
log ('C','I',' ',nullstr);
logdat();
/*
* Grab a mess of memory.
* 16k max. Leave at least 8k for heap.
*/
#ifndef MCH_AMIGA
avl = _memavl();
if ( (avl - minheap) > maxscr ) scrmax = maxscr;
else scrmax = avl - minheap;
if (scrmax < minscr)
{
printf("Too little memory available.\n");
exit(1);
}
tmp = (TMP *) malloc(scrmax);
printf("[%u] %u free space, %u used.\n", log_mon, avl, scrmax + minheap);
#else
/* get free space in Kb */
avl = (int)(AvailMem(MEMF_CHIP)>>10);
fast = (int)(AvailMem(MEMF_FAST)>>10);
/* Just ask for the whole 16Kb ... If it's not there try scrmin */
scrmax = maxscr;
tmp = (TMP *) malloc((size_t)maxscr);
if(tmp == 0) {
tmp = (TMP *) malloc((size_t)minscr);
scrmax = minscr;
if(tmp == 0) {
endtimer();
cleanser();
freefcb();
closeterm();
printf("Not enough memory available.\n");
exit(1);
}
}
/* amiga doesn't need a 'heap' */
sprintf(tstr,"%uKb Chip, %uKb Fast Memory. %uKb will be used.\n",
avl,fast, scrmax >> 10);
ttputs(tstr);
#endif
dirmax = scrmax / sizeof(DIRENT);
seed();
#ifndef MCH_AMIGA
dosinit();
#endif
/*
* Set initial beacon text.
*/
setfwd();
clsmsg();
clsusr();
#ifdef MCH_AMIGA
/* Let sysop know which of my options are set from the config.mb file.*/
printopts();
#endif
}
seed()
{
register short curmin;
curtim(); curmin=10 * (l_time[2]-'0') + (l_time[3]-'0');
srand(curmin);
}
/*
* Read the rest of the configuration file,
* after the port and path definitions.
*/
rdcnf()
{
register int i;
/*
* Login message.
*/
motd = rdmstr();
/*
* Prompts.
*/
bbmenu = rdstr(); /* Prompt for connected bbs */
symenu = rdstr(); /* Local and remote sysop prompt */
rmenus = rdstr(); /* User prompt */
/*
* Who are we?
*/
fgets (port->line, linelen, port->fl);
pcall (tcall, port->line);
/*
* Where are we?
*/
qth = rdstrnl();
/*
* Who is our name server?
*/
fgets (port->line, cmdlen, port->fl);
pcall (wpcall, port->line);
/*
* File names and directory paths used by MailBox.
*/
helpfile = rdstrnl();
infofile = rdstrnl();
fwdfile = rdstrnl();
lgfile = rdstrnl();
monfile = rdstrnl();
mbfile = rdstrnl();
mbbfile = rdstrnl();
usfile = rdstrnl();
usbfile = rdstrnl();
msgdir = rdstrnl();
bidfile = rdstrnl();
hrdfile = rdstrnl();
stfile = rdstrnl();
#ifdef MCH_AMIGA
/* Change some of the above filenames so that they include the port id */
portfile();
#endif
hrdmax = rdnumb();
/*
* Automatic mail untangle at what hour?
* NO or YES hh Where hh is the untangle hour 0-23
*/
if (kw())
{
s_param setbit s_unt;
unt_hr = atoi(port->fld[1]);
}
/*
* Give time slice back to DESQview?
*/
if (kw()) s_flag setbit s_dv;
#ifdef MCH_AMIGA
/* The multi-user version requires this whole locking mechanism OFF
and multi-user is now the default.
*/
s_flag clrbit s_dv;
#endif
/*
* Prompt for user info?
*/
if (kw()) s_prompt setbit s_p_name;
if (kw()) s_prompt setbit s_p_home;
if (kw()) s_prompt setbit s_p_zip;
if (kw()) s_prompt setbit s_p_qth;
/*
* Logging
*/
if (kw()) s_param setbit s_log_on;
if (kw()) s_param setbit s_log_gate;
if (kw()) s_param setbit s_log_file;
if (kw()) s_param setbit s_log_msg;
if (kw()) s_param setbit s_log_loc;
/*
* Control characters.
*/
achar = cchr();
rchar = cchr();
tchar = cchr();
wchar = cchr();
pausemsg = rdstr();
/* Text for local display of user call. */
mumsg = rdstr();
/* Text to send when get connect request. */
reqmsg = rdstr();
/* Various "talk to the owner" texts. */
talkm1 = rdstr();
talkm2 = rdstr();
talkm3 = rdstr();
talkm4 = rdstr();
/* MailBox messages. */
for (i = 0; i < num_mm; i++) mm[i] = rdstr();
/* Max calls in unread mail list. */
ufwdm = rdnumb();
bfwdm = rdnumb();
/* Max days for a bid file record. */
bidnum = atoi(port->fld[1]);
/* Kill regular message after forward? */
if (kw()) s_param setbit s_kill;
/* Kill F message after forward? */
if (kw()) s_param setbit s_fkill;
/* Generate service msg after KT? */
if (kw()) s_param setbit s_svc;
/* Enable ET command? */
if (kw()) s_param setbit s_edtfc;
if (*port->fld[1] is 'Y') s_param setbit s_ping;
/* How many days before a message becomes stale */
tstaleb = rdnumb();
if(*port->fld[1] is 'Y') s_flag setbit s_bkill;
tstale1 = atoi (port->fld[2]); /* 1st time period days */
rstale1 = atoi (port->fld[3]); /* 1st period read count */
tstale2 = atoi (port->fld[4]); /* 2nd time period days */
rstale2 = atoi (port->fld[5]); /* 2nd period read count */
tstale3 = atoi (port->fld[6]); /* 3rd time period days */
rstale3 = atoi (port->fld[7]); /* 3rd period read count */
tstalen = rdnumb(); if(*port->fld[1] is 'Y') s_flag setbit s_nkill;
tstaleu = rdnumb(); if(*port->fld[1] is 'Y') s_flag setbit s_ukill;
/* Upload/download prompts. */
fm = rdstr();
/* User file text. */
for (i = 0; i < num_um; i++) um[i] = rdstr();
remnl(um[0]);
/* Error/status messages. */
mcant = rdstr();
mfind = rdstr();
mprot = rdstr();
mexst = rdstr();
mtime = rdstr();
mwhat = rdstr();
mdone = rdstr();
mnport = rdstr();
mndir = rdstr();
mnfile = rdstr();
mnmsg = rdstr();
minuse = rdstr();
#ifdef MCH_AMIGA
#endif
#ifdef NEWPASS
numpass = initpwd();
sprintf(tmpstr,"NUMPASS = %d\n",numpass);
ttputs(tmpstr);
#else
keylst = rdstr();
#endif
}
#ifdef MCH_AMIGA
printopts()
{
register int i;
register char flag;
flag = 0;
for(i=0;i<NUMOPTS;i++) {
if(optflags[i] == 0) {
if(flag == 0) {
ttputs("\nThe following options are turned OFF - ");
flag = 1;
}
ttputc('A'+i);
}
}
if(flag) {
ttputc('\n');
}
}
setinit(file)
char *file;
{
/* On the AMIGA opening the config file and doing rdports() are done
before the window and serial ports are opened to allow the user to
set configuration options which may affect the opening of the
window or serial port.
*/
porthd = (PORTS *) malloc(sizeof(PORTS));
porthd->cmd = (char *) malloc((size_t)cmdlen);
porthd->line = (char *) malloc((size_t)linelen);
ioport(porthd);
/*
* Open the configuration file.
*/
if ((port->fl = fopen(file, "r")) is NULL)
{
printf("Missing config file - ");
printf("Cannot open %s\n", file); return(1);
}
/*
* Read the configuration file, set everything up.
*/
rdports();
return(0);
}
#endif